home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / POLL.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  108 lines

  1. #ifndef _LINUX_POLL_H
  2. #define _LINUX_POLL_H
  3.  
  4. #include <asm/poll.h>
  5.  
  6. #ifdef __KERNEL__
  7.  
  8. #include <linux/wait.h>
  9. #include <linux/string.h>
  10. #include <linux/mm.h>
  11. #include <asm/uaccess.h>
  12.  
  13.  
  14. struct poll_table_entry {
  15.     struct file * filp;
  16.     struct wait_queue wait;
  17.     struct wait_queue ** wait_address;
  18. };
  19.  
  20. typedef struct poll_table_struct {
  21.     struct poll_table_struct * next;
  22.     unsigned int nr;
  23.     struct poll_table_entry * entry;
  24. } poll_table;
  25.  
  26. #define __MAX_POLL_TABLE_ENTRIES ((PAGE_SIZE - sizeof (poll_table)) / sizeof (struct poll_table_entry))
  27.  
  28. extern void __pollwait(struct file * filp, struct wait_queue ** wait_address, poll_table *p);
  29.  
  30. extern inline void poll_wait(struct file * filp, struct wait_queue ** wait_address, poll_table *p)
  31. {
  32.     if (p && wait_address)
  33.         __pollwait(filp, wait_address, p);
  34. }
  35.  
  36. /*
  37.  * For the kernel fd_set we use a fixed set-size for allocation purposes.
  38.  * This set-size doesn't necessarily bear any relation to the size the user
  39.  * uses, but should preferably obviously be larger than any possible user
  40.  * size (NR_OPEN bits).
  41.  *
  42.  * We need 6 bitmaps (in/out/ex for both incoming and outgoing), and we
  43.  * allocate one page for all the bitmaps. Thus we have 8*PAGE_SIZE bits,
  44.  * to be divided by 6. And we'd better make sure we round to a full
  45.  * long-word (in fact, we'll round to 64 bytes).
  46.  */
  47.  
  48.  
  49. #define KFDS_64BLOCK ((PAGE_SIZE/(6*64))*64)
  50. #define KFDS_NR (KFDS_64BLOCK*8 > NR_OPEN ? NR_OPEN : KFDS_64BLOCK*8)
  51. typedef unsigned long kernel_fd_set[KFDS_NR/__NFDBITS];
  52.  
  53. /*
  54.  * Scaleable version of the fd_set.
  55.  */
  56.  
  57. typedef struct {
  58.     unsigned long *in, *out, *ex;
  59.     unsigned long *res_in, *res_out, *res_ex;
  60. } fd_set_bits;
  61.  
  62. /*
  63.  * How many longwords for "nr" bits?
  64.  */
  65. #define FDS_BITPERLONG    (8*sizeof(long))
  66. #define FDS_LONGS(nr)    (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
  67. #define FDS_BYTES(nr)    (FDS_LONGS(nr)*sizeof(long))
  68.  
  69. /*
  70.  * We do a VERIFY_WRITE here even though we are only reading this time:
  71.  * we'll write to it eventually..
  72.  *
  73.  * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
  74.  */
  75. static inline
  76. int get_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
  77. {
  78.     nr = FDS_BYTES(nr);
  79.     if (ufdset) {
  80.         int error;
  81.         error = verify_area(VERIFY_WRITE, ufdset, nr);
  82.         if (!error && __copy_from_user(fdset, ufdset, nr))
  83.             error = -EFAULT;
  84.         return error;
  85.     }
  86.     memset(fdset, 0, nr);
  87.     return 0;
  88. }
  89.  
  90. static inline
  91. void set_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
  92. {
  93.     if (ufdset)
  94.         __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
  95. }
  96.  
  97. static inline
  98. void zero_fd_set(unsigned long nr, unsigned long *fdset)
  99. {
  100.     memset(fdset, 0, FDS_BYTES(nr));
  101. }
  102.  
  103. extern int do_select(int n, fd_set_bits *fds, long *timeout);
  104.  
  105. #endif /* KERNEL */
  106.  
  107. #endif /* _LINUX_POLL_H */
  108.